<!-- 功能：windows共享设置弹窗 | 作者：menghao.yan | 邮箱：yxs2615@163.com | 时间：2023年08月21日 22:59:06 -->
<template>
  <!-- 弹出框 -->
  <a-modal v-model:open="visible" title="Windows共享设置" width="800px" class="y-modal" okText="创建" @ok="onSubmit" @cancel="onCancel">
    <a-form :label-col="{ span: 6 }" :wrapper-col="{span: 14}">
      <a-row :gutter="24">
        <a-col :span="12">
          <a-card>
            <a-form-item label="工作组" v-bind="validateInfos.gongZuoZu">
              <a-radio-group v-model:value="modelRef.gongZuoZu">
                <a-radio :style="radioStyle" value="queSheng">缺省</a-radio>
                <a-radio :style="radioStyle" value="ziDingYi">
                  自定义
                  <a-input v-model="modelRef.gongZuoZuZiDingYi" placeholder="请输入自定义工作组" v-if="modelRef.gongZuoZu == 'ziDingYi'" />
                </a-radio>
              </a-radio-group>
            </a-form-item>
            <a-form-item label="服务描述" v-bind="validateInfos.fuWuMiaoShu">
              <a-radio-group v-model:value="modelRef.fuWuMiaoShu">
                <a-radio :style="radioStyle" value="queSheng">缺省</a-radio>
                <a-radio :style="radioStyle" value="ziDingYi">
                  自定义
                  <a-input v-model="modelRef.fuWuMiaoShuZiDingYi" placeholder="请输入自定义工作组" v-if="modelRef.fuWuMiaoShu == 'ziDingYi'" />
                </a-radio>
              </a-radio-group>
            </a-form-item>
          </a-card>
        </a-col>
        <a-col :span="12">
          <a-card>
            <a-form-item label="服务名称" v-bind="validateInfos.fuWuMingCheng">
              <a-input v-model="modelRef.fuWuMingCheng" placeholder="请输入服务名称" />
            </a-form-item>
            <a-form-item label="服务别名" v-bind="validateInfos.fuWuMingBieMing">
              <a-input v-model="modelRef.fuWuMingBieMing" placeholder="请输入服务别名" />
            </a-form-item>
            <a-form-item label="安全性" v-bind="validateInfos.anQuanXing">
              <a-select v-model:value="modelRef.anQuanXing" placeholder="请选择安全性">
                <a-select-option value="benDiRenZheng">本地认证</a-select-option>
                <a-select-option value="miMaFuWuQi">密码服务器</a-select-option>
              </a-select>
            </a-form-item>
          </a-card>
        </a-col>
      </a-row>
    </a-form>
  </a-modal>
</template>

<script setup>
const props = defineProps({
  visible: {
    type: Boolean,
    default: false
  }
})

const radioStyle = reactive({
  display: 'flex',
  height: '30px',
  lineHeight: '30px'
})
const { visible } = toRefs(props)

// 定义组件的事件
const emits = defineEmits(['update:visible'])

import { Form } from 'ant-design-vue'

const useForm = Form.useForm

const modelRef = reactive({
  gongZuoZu: 'queSheng',
  gongZuoZuZiDingYi: '',
  fuWuMiaoShu: 'queSheng',
  fuWuMiaoShuZiDingYi: '',
  fuWuMingCheng: '',
  fuWuMingBieMing: '',
  anQuanXing: 'benDiRenZheng'
})

const rulesRef = reactive({
  gongZuoZu: [
    {
      required: true,
      message: '请选择工作组'
    }
  ],

  fuWuMiaoShu: [
    {
      required: true,
      message: '请选择服务描述'
    }
  ],
  fuWuMingCheng: [
    {
      required: true,
      message: '请输入服务名称'
    }
  ],
  fuWuMingBieMing: [
    {
      required: true,
      message: '请输入服务别名'
    }
  ],
  anQuanXing: [
    {
      required: true,
      message: '请选择安全性'
    }
  ]
})

const { resetFields, validate, validateInfos, mergeValidateInfo } = useForm(modelRef, rulesRef)
const onSubmit = () => {
  validate()
    .then(() => {
      console.log('Windows共享设置>', toRaw(modelRef))
      onCancel()
    })
    .catch(err => {
      console.log('error', err)
    })
}

const onCancel = () => {
  // 触发自定义事件来通知父组件关闭弹窗
  emits('update:visible', false)
}
</script>

<style scoped>
.ant-row {
  margin-bottom: 10px;
}
</style>